package com.mdd.admin.controller.app;

import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mdd.common.aop.NotLogin;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.entity.user.UserTest;
import com.mdd.common.mapper.user.UserTestMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/app/test")
@Api(tags = "测试用")
@Slf4j
public class AppTest {

    @Resource
    UserTestMapper userTestMapper;

//    @NotLogin
    @GetMapping("/test")
    @ApiOperation(value="测试")
    public AjaxResult<Object> sendSms() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("data", "测试用");
        log.info("测试用: {}", jsonObject);
        return AjaxResult.success(jsonObject);
    }

    @PostMapping("/addUserTest")
    @NotLogin
    public AjaxResult<Object> addUserTest(@RequestBody UserTest userTest) {
        userTestMapper.insert(userTest);
        return AjaxResult.success("添加成功");
    }

    @PostMapping("/selectUserTest")
    @NotLogin
    public AjaxResult<Object> selectUserTest(@RequestBody UserTest userTest) {
//        UserTest userTest1 = userTestMapper.selectById(918);

//        Long aLong = userTestMapper.selectCount(null);

        QueryWrapper<UserTest> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", "测试2");
        List<UserTest> userTests = userTestMapper.selectList(queryWrapper);

        return AjaxResult.success(userTests);
    }

}
